package com.mark.mall.web.platform.dto;

import com.mark.mall.web.platform.entity.Product;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.util.StringUtils;

import java.math.BigDecimal;

/**
 * @author admin
 * Created on 2021/3/3 14:08
 */
@Data
@ApiModel("首页物料列表")
@NoArgsConstructor
public class ProductDTO {
    @ApiModelProperty(value = "物料id")
    private String id;
    @ApiModelProperty(value = "物料价格")
    private BigDecimal price;
    @ApiModelProperty(value = "物料编码")
    private String code;
    @ApiModelProperty(value = "物料名称")
    private String name;
    @ApiModelProperty(value = "上架数量")
    private Integer shelfNum;
    @ApiModelProperty(value = "物料单位")
    private String unit;
    @ApiModelProperty(value = "物料主图")
    private String mainUrl;

    public ProductDTO(Product product) {
        this.id = product.getId();
        this.code = !StringUtils.isEmpty(product.getCode()) ? product.getCode() : "";
        this.price = product.getPrice();
        this.name = !StringUtils.isEmpty(product.getName()) ? product.getName() : "";
        this.shelfNum = !StringUtils.isEmpty(product.getShelfnum()) ? product.getShelfnum() : 0;
        this.unit = !StringUtils.isEmpty(product.getUnit()) ? product.getUnit() : "";
        this.mainUrl = !StringUtils.isEmpty(product.getMainurl()) ? product.getMainurl() : "";
    }
}
